import useAppContext from "@/hooks/useAppContext";
import { View } from "@tarojs/components";
import type { ComponentType, ReactNode } from "react";
import styles from "./index.module.less";

function IsInitailzed<T extends Record<string, any>>(
  Comp: ComponentType<T>,
  Loading?: ReactNode
) {
  return (props) => {
    const isInitail = useAppContext((state) => state.isInitialized);
    if (isInitail) {
      return <Comp {...props} />;
    }

    if (Loading) {
      return Loading;
    }

    return <View className={styles["loading-wrapper"]}>loadnig...</View>;
  };
}

export default IsInitailzed;
